/**
 * 
 */
package com.roshan.web.security.handlers;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler;

import com.roshan.web.security.service.ICookieService;

public class RoarLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler {

    @Autowired
    private ICookieService cookieService;

    private @Value("${roar.security.cookie.name}")
    String securityCookieName;

    private @Value("${roar.security.cookies.timeout.name}")
    String timeoutCookieName;

    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
            throws IOException, ServletException {
        this.cookieService.removeCookie(this.securityCookieName, request, response);
        this.cookieService.removeCookie(this.timeoutCookieName, request, response);
        super.handle(request, response, authentication);

    }

}
